package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.BusZhncCrop;
import com.ruoyi.business.service.IBusZhncCropService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 种植面积Controller
 * 
 * @author ruoyi
 * @date 2023-07-30
 */
@RestController
@RequestMapping("/zhnc/planting")
@Api(tags = "智慧农场-种植面积")
public class BusZhncCropController extends BaseController
{
    @Autowired
    private IBusZhncCropService busZhncCropService;

    /**
     * 查询种植面积列表
     */
    @GetMapping("/list")
    @ApiOperation("列表 ")
    public TableDataInfo list(BusZhncCrop busZhncCrop)
    {
        startPage();
        List<BusZhncCrop> list = busZhncCropService.selectBusZhncCropList(busZhncCrop);
        return getDataTable(list);
    }

    /**
     * 导出种植面积列表
     */
    @PreAuthorize("@ss.hasPermi('zhnc:planting:export')")
    @Log(title = "种植面积", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusZhncCrop busZhncCrop)
    {
        List<BusZhncCrop> list = busZhncCropService.selectBusZhncCropList(busZhncCrop);
        ExcelUtil<BusZhncCrop> util = new ExcelUtil<BusZhncCrop>(BusZhncCrop.class);
        util.exportExcel(response, list, "种植面积数据");
    }

    /**
     * 获取种植面积详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhnc:planting:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busZhncCropService.selectBusZhncCropById(id));
    }

    /**
     * 新增种植面积
     */
    @PreAuthorize("@ss.hasPermi('zhnc:planting:add')")
    @Log(title = "种植面积", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusZhncCrop busZhncCrop)
    {
        return toAjax(busZhncCropService.insertBusZhncCrop(busZhncCrop));
    }

    /**
     * 修改种植面积
     */
    @PreAuthorize("@ss.hasPermi('zhnc:planting:edit')")
    @Log(title = "种植面积", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusZhncCrop busZhncCrop)
    {
        return toAjax(busZhncCropService.updateBusZhncCrop(busZhncCrop));
    }

    /**
     * 删除种植面积
     */
    @PreAuthorize("@ss.hasPermi('zhnc:planting:remove')")
    @Log(title = "种植面积", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busZhncCropService.deleteBusZhncCropByIds(ids));
    }
}
